<template>
    <web-view :src="pageUrl" />
</template>

<script setup>
  import { onLoad } from '@dcloudio/uni-app';
  import { ref } from 'vue';
  import healthCard from '../static/ElectronicHealthCard';
  import healthCardUtil from '@/utils/healthCard/index';

  const pageUrl = ref('');
  const redirectURL = ref('');

  onLoad(options => {
    init(options);
  });

  async function init(options) {
    try {
      console.log('faceUrl【options】', options);
      healthCardUtil.showLoad();
      const { redirectUrl, orderId, verifyType } = options;
      redirectURL.value = redirectUrl;
      const verifyOrderId = await healthCard.verifyFlow({
        orderId,
        verifyType,
      });
      healthCardUtil.hideLoad();
      console.log('faceUrl success', verifyOrderId);
      pageUrl.value = `${decodeURIComponent(redirectUrl)}&verify_order_id=${
        verifyOrderId || -1
      }`;
      console.log('pageUrl', pageUrl.value);
    } catch (err) {
      console.log('faceUrl fail', err);
      pageUrl.value = `${decodeURIComponent(
        redirectURL.value,
      )}&verify_order_id=-1`;
      console.log('pageUrl', pageUrl.value);
      healthCardUtil.hideLoad(1500);
    }
  }
</script>
